{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true,
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "# Pull Marquee ESG Analytics with GS Quant\n",
    "\n",
    "First get your portfolio and choose the date for which you'd like ESG data:"
   ]
  },
  {
   "cell_type": "code",
   "source": [
    "import datetime as dt\n",
    "import warnings\n",
    "\n",
    "from gs_quant.api.gs.esg import ESGMeasure\n",
    "from gs_quant.markets.portfolio_manager import PortfolioManager\n",
    "from gs_quant.session import GsSession, Environment\n",
    "from IPython.display import display\n",
    "\n",
    "GsSession.use(Environment.PROD)\n",
    "warnings.filterwarnings(\"ignore\", category=RuntimeWarning)\n",
    "\n",
    "portfolio_id= 'MPWQQ8B05FKPCCH6'\n",
    "date = dt.date(2021, 9, 1)\n",
    "\n",
    "pm = PortfolioManager(portfolio_id)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "execution_count": null,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "source": [
    "Then get any of the following ESG Analytics:"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "print('Portfolio Summmary:')\n",
    "display(pm.get_esg_summary(pricing_date=date))"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "print('Quintile Breakdown:')\n",
    "display(pm.get_esg_quintiles(\n",
    "    measure=ESGMeasure.ES_PERCENTILE,\n",
    "    pricing_date=date\n",
    "))"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "source": [
    "print('Sector Breakdown:')\n",
    "display(pm.get_esg_by_sector(\n",
    "    measure=ESGMeasure.ES_PERCENTILE,\n",
    "    pricing_date=date\n",
    "))"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "execution_count": null,
   "outputs": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "print('Region Breakdown:')\n",
    "display(pm.get_esg_by_region(\n",
    "    measure=ESGMeasure.ES_PERCENTILE,\n",
    "    pricing_date=date\n",
    "))"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "print(f'Top Ten Ranked:')\n",
    "display(pm.get_esg_top_ten(\n",
    "    measure=ESGMeasure.ES_PERCENTILE,\n",
    "    pricing_date=date\n",
    "))"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "print(f'Bottom Ten Ranked:')\n",
    "display(pm.get_esg_bottom_ten(\n",
    "    measure=ESGMeasure.ES_PERCENTILE,\n",
    "    pricing_date=date\n",
    "))\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}